#!/usr/bin/env bash
set -e
if [[ -z "$1" ]]; then
  echo 'Usage '$0' [path-to-project]'
  exit 1
fi

if [[ ! -d "$1" ]]; then
  echo "Path '$1' does not exist or its not a directory"
  exit 1
fi

ADDON_PATH=$(cd `dirname $0` && pwd)
cp -r $ADDON_PATH/skel/* $1/

pushd "$1/app/client"
ln -s ../static asset
popd

pushd "$1"
for file in $ADDON_PATH/patches/*; do
  patch -p1 < "$file"
done
popd

# sed  -i.bak '/^  env\-storage\:[^$]*$/a\
#   npm-storage:'$'\n' "$1/docker/containers/compose.yml" && rm -f "$_.bak"
